function EditBrand(btn,id,name){
	name = unescape(name);
	var admin = document.getElementById("BrandsAdmin");
	var form = document.getElementById("BrandsAdminEdit");
	var table = btn.parentNode.parentNode.parentNode;
	var tds = btn.parentNode.parentNode.getElementsByTagName("td");
	var inptID = document.getElementById("edit_brand_id");
	var inptNAME = document.getElementById("edit_brand_name");
	
	var state = table.getAttribute("state");
	state = state>0?1:-1;
	
	var stateObj = table.stateObj;
	var prev = table.getAttribute("previousVal");
	
	if(stateObj && stateObj!=btn){ // klik na drugi button
		var tds = stateObj.parentNode.parentNode.getElementsByTagName("td");
		tds[1].innerHTML = prev;
		
		
		var tds = btn.parentNode.parentNode.getElementsByTagName("td");
		table.setAttribute("previousVal",tds[1].innerHTML);
		tds[1].innerHTML = "";
		tds[1].appendChild(form);
		inptID.value=id;
		inptNAME.value=name;
		inptNAME.focus();
		inptNAME.select();
		state = -1;
	}else if(state>0){	// cancel edit
		form.style.display="none";
		admin.appendChild(form);
		tds[1].innerHTML = prev;
	}else{			// edit
		table.setAttribute("previousVal",name);
		inptID.value=id;
		inptNAME.value=name;
		inptNAME.focus();
		inptNAME.select();
		
		tds[1].innerHTML = "";
		tds[1].appendChild(form);
		form.style.display = "block";
	}
	
	table.setAttribute("state",(-1)*state);
	table.stateObj = btn;
}
function DeleteBrand(id,name){
	name = unescape(name);
	if(confirm("Da li želite da obrišete brend: "+name)){
		LoadRSDoc("brands.php?a=delete&id="+id,'afterDeleteBrand');
	}
}
function afterDeleteBrand(response){
	var tmp = response.split("{!}",2);
	var code= parseInt(tmp[0]);
	var msg = tmp[1];
	
	alert(msg);
	if(!code){
		refreshFilter();
	}
}
function afterEditBrand(response){
	var tmp = response.split("{!}",2);
	var code= parseInt(tmp[0]);
	var msg = tmp[1];
	alert(msg);
	if(!code){
		refreshFilter();
	}
}
function refreshFilter(){
	var kword = trim(document.getElementById("kword").value);
	var pages = document.getElementById("PageFilter").getElementsByTagName("a");
	var page=1;
	for(var i=0; i<pages.length; i++){
		if(pages[i].id=="current"){
			page=trim(pages[i].innerHTML);
			break;
		}
	}
	LoadRSDoc("brands.php?kword="+escape(kword)+"&page="+page,'setContent');
}